package com.scott.controller;

import com.scott.controller.frontend.MainPageController;
import com.scott.controller.superadmin.HeadLineOperationController;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName DispatcherServlet
 * @Description
 * @Author 47980
 * @Date 2020/6/9 6:26
 * @Version V_1.0
 **/
@Slf4j
@WebServlet("/")
public class DispatcherServlet extends HttpServlet {

    /**
     * 获取请求路径 req.getServletPath()
     * 获取请求方法 req.getMethod()
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("请求路径："+req.getServletPath());
        System.out.println("请求方法："+req.getMethod());
        if (req.getServletPath() == "/frontend/getmainpageinfo" && req.getMethod().equals("GET")) {
            new MainPageController().getMainPageInfo(req, resp);
        } else if (req.getServletPath() == "/superadmin/addheadline" && req.getMethod().equals("POST")) {
            new HeadLineOperationController().addHeadLine(req, resp);
        }
    }
}
